// Mock数据生成工具类
export class MockDataGenerator {
  // 生成随机数
  static random(min: number, max: number): number {
    return Math.floor(Math.random() * (max - min + 1)) + min
  }

  // 生成随机小数
  static randomFloat(min: number, max: number, decimals = 2): number {
    return parseFloat((Math.random() * (max - min) + min).toFixed(decimals))
  }

  // 生成时间序列数据
  static generateTimeSeriesData(count: number, min: number, max: number) {
    const now = new Date()
    return Array.from({ length: count }, (_, i) => {
      const time = new Date(now.getTime() - (count - i - 1) * 1000)
      return {
        time: time.toLocaleTimeString('zh-CN'),
        value: this.randomFloat(min, max)
      }
    })
  }

  // 生成区域数据
  static generateRegionData() {
    const regions = ['华北', '华东', '华南', '华中', '西南', '西北', '东北']
    return regions.map(region => ({
      name: region,
      value: this.random(1000, 10000)
    }))
  }

  // 生成3D柱状图数据
  static generate3DBarData() {
    const categories = ['产品A', '产品B', '产品C', '产品D', '产品E', '产品F']
    const months = ['1月', '2月', '3月', '4月', '5月', '6月']
    const data: [number, number, number][] = []

    months.forEach((_, i) => {
      categories.forEach((_, j) => {
        data.push([i, j, this.random(50, 500)])
      })
    })

    return { categories, months, data }
  }

  // 生成仪表盘数据
  static generateGaugeData() {
    return {
      cpu: this.randomFloat(20, 90),
      memory: this.randomFloat(30, 85),
      disk: this.randomFloat(40, 80),
      network: this.randomFloat(10, 95)
    }
  }

  // 生成地图数据
  static generateMapData() {
    const provinces = [
      { name: '北京', value: this.random(500, 2000), coord: [116.4074, 39.9042] },
      { name: '上海', value: this.random(500, 2000), coord: [121.4737, 31.2304] },
      { name: '广东', value: this.random(500, 2000), coord: [113.2644, 23.1291] },
      { name: '浙江', value: this.random(500, 2000), coord: [120.1536, 30.2875] },
      { name: '江苏', value: this.random(500, 2000), coord: [118.7969, 32.0603] },
      { name: '四川', value: this.random(500, 2000), coord: [104.0665, 30.5723] },
      { name: '湖北', value: this.random(500, 2000), coord: [114.3055, 30.5931] },
      { name: '山东', value: this.random(500, 2000), coord: [117.0208, 36.6683] },
    ]
    return provinces
  }

  // 生成实时数据流
  static createRealTimeDataStream(callback: (data: any) => void, interval = 2000) {
    const timer = setInterval(() => {
      callback({
        timestamp: new Date().toLocaleTimeString('zh-CN'),
        value: this.randomFloat(0, 100),
        cpu: this.randomFloat(20, 90),
        memory: this.randomFloat(30, 85),
        requests: this.random(100, 1000),
        users: this.random(50, 500)
      })
    }, interval)

    return () => clearInterval(timer)
  }
}

// 统计数据服务
export const statsData = {
  getTotalVisits: () => MockDataGenerator.random(100000, 999999),
  getTotalUsers: () => MockDataGenerator.random(10000, 99999),
  getTotalRevenue: () => MockDataGenerator.randomFloat(100000, 999999, 2),
  getConversionRate: () => MockDataGenerator.randomFloat(1, 10, 2)
}
